<?php
class Sef
{
	var $control = '';
	var $action = '';
	var $get = array();
	var $querystring = '';
	
	function __construct()
	{
		$pos = strpos($_SERVER['QUERY_STRING'], '.');
		if($pos !== false){
			$querystring = substr($_SERVER['QUERY_STRING'], 0, $pos);
		}
		$segment = explode('/', $querystring);
		$clip = explode('-', $segment[2]);
		$get_arr = array();
		$get_arr['c'] = $segment[0];
		$get_arr['a'] = $segment[1];
		
		foreach($clip as $key => $val){
			if ($key%2 == 0) {
				$get_arr[$val] = $clip[$key+1];
			}
		}
		$this->get =  $get_arr;
	}
	
	function getParams()
	{
		return $this->get;
	}
	
	function buildUri($c='',$a='')
	{
		$c = empty($c) ? $this->get['c'] : $c;
		$a = empty($a) ? $this->get['a'] : $a;
		$c_a_uri = $c.'/'.$a;
		return $c_a_uri;
	}
	
	function buildParam($arr='')
	{
		if (!empty($arr) && is_array($arr)) {
		
			foreach($arr as $key => $val) {
				$param[] = $key."-".$val;
			}
		}
		$param_uri = '';
		if (!empty($param)) {
			$param_uri = implode('-', $param);
		}
		
		return $param_uri;
	}
	
	function buildLink($c='', $a='', $str_url='')
	{
		$uri = empty($param_uri) ? '' : '/'.$str_url;
		$url = ROOT_URL.'/'.$this->buildUri($c, $a).$uri.$this->buildSuffix();
		return $url;
	}
	
	function buildSuffix($str='')
	{
		return empty($str) ? '.html' :'.'.$str;
	}
	
}



?>